﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;

namespace SaunaClient.Model.Network
{
    [Serializable]
    public class NetworkSetting
    {
        private FtpBaseSetting ftpBaseSetting;
        private TcpBaseSetting tcpBaseSetting;
        private string logFileDirectory;

        private const string DEFAULT_FTP_HOST_ADDRESS = "localhost";
        private const int DEFAULT_FTP_PORT_NUMBER = 21;
        private const bool DEFAULT_FTP_USE_SSL = true;
        private const string DEFAULT_FTP_USER_NAME = "SaunaFtpUser";
        private const string DEFAULT_FTP_PASSWORD_NAME = "pass333";
        private const string DEFAULT_FTP_SERVER_DIRECTORY = "/";
        private const string DEFAULT_FTP_LOCAL_DIRECTORY = @"c:\work\";

        private const string DEFAULT_TCP_HOST_ADDRESS = "localhost";
        private const int DEFAULT_TCP_PORT_NUMBER = 1723;
        private const bool DEFAULT_TCP_USE_SSL = true;

        private const string DEFAULT_LOG_FILE_DIRECTORY = @"\";

        private const string FILE_LOGGER = "FileLogger";
        private const string SFTP_LOG_MESSAGE = "Command: {0}";

        /// <summary>
        /// Default Constructor
        /// </summary>
        public NetworkSetting()
        {
            ftpBaseSetting = new FtpBaseSetting(DEFAULT_FTP_HOST_ADDRESS, DEFAULT_FTP_PORT_NUMBER, DEFAULT_FTP_USE_SSL,
                                                DEFAULT_FTP_USER_NAME, DEFAULT_FTP_PASSWORD_NAME, DEFAULT_FTP_SERVER_DIRECTORY,
                                                DEFAULT_FTP_LOCAL_DIRECTORY, DEFAULT_LOG_FILE_DIRECTORY);

            tcpBaseSetting = new TcpBaseSetting(DEFAULT_TCP_HOST_ADDRESS, DEFAULT_TCP_PORT_NUMBER, DEFAULT_TCP_USE_SSL, 
                                                DEFAULT_LOG_FILE_DIRECTORY);

            this.logFileDirectory = DEFAULT_LOG_FILE_DIRECTORY;
        }

        /// <summary>
        /// Constructor
        /// </summary>
        public NetworkSetting(string ftpHostAddress, string ftpUserName, string ftpPassword,
                              string ftpServerDirectory, string ftpLocalDirectory, bool ftpSsl,
                              int ftpPortNumber, string tcpHostAddress, int tcpPortNumber, bool tcpSsl, string logFileDirectory)
        {
            ftpBaseSetting = new FtpBaseSetting(ftpHostAddress, ftpPortNumber, ftpSsl, ftpUserName, 
                                                ftpPassword, ftpServerDirectory, ftpLocalDirectory, logFileDirectory);

            tcpBaseSetting = new TcpBaseSetting(tcpHostAddress, tcpPortNumber, tcpSsl, logFileDirectory);

            this.logFileDirectory = logFileDirectory;
        }

        public NetworkSetting Clone()
        {
            NetworkSetting destinationNetworkSetting = new NetworkSetting();

            destinationNetworkSetting = new NetworkSetting(FtpHostAddress, FtpUserName, FtpPassword, FtpServerDirectory,
                                                               FtpLocalDirectory, FtpSsl, FtpPortNumber, TcpHostAddress,
                                                               TcpPortNumber, TcpSsl, LogFileDirectory);
            return destinationNetworkSetting;
        }

        public void Copy(NetworkSetting sourceNetworkSetting)
        {
            FtpHostAddress = sourceNetworkSetting.FtpHostAddress;
            FtpUserName = sourceNetworkSetting.FtpUserName;
            FtpPassword = sourceNetworkSetting.FtpPassword;
            FtpServerDirectory = sourceNetworkSetting.FtpServerDirectory;
            FtpLocalDirectory = sourceNetworkSetting.FtpLocalDirectory;
            FtpPortNumber = sourceNetworkSetting.FtpPortNumber;
            FtpSsl = sourceNetworkSetting.FtpSsl;
            TcpHostAddress = sourceNetworkSetting.TcpHostAddress;
            TcpPortNumber = sourceNetworkSetting.TcpPortNumber;
            TcpSsl = sourceNetworkSetting.TcpSsl;
            LogFileDirectory = sourceNetworkSetting.LogFileDirectory;
        }

        public string FtpHostAddress
        {
            get { return ftpBaseSetting.HostAddress; }
            set { ftpBaseSetting.HostAddress = value; }
        }

        public string FtpUserName
        {
            get { return ftpBaseSetting.UserName; }
            set { ftpBaseSetting.UserName = value; }
        }

        public string FtpPassword
        {
            get { return ftpBaseSetting.Password; }
            set { ftpBaseSetting.Password = value; }
        }

        public string FtpServerDirectory
        {
            get { return ftpBaseSetting.ServerDirectory; }
            set { ftpBaseSetting.ServerDirectory = value; }
        }

        public string FtpLocalDirectory
        {
            get { return ftpBaseSetting.LocalDirectory; }
            set { ftpBaseSetting.LocalDirectory = value; }
        }

        public bool FtpSsl
        {
            get { return ftpBaseSetting.UseSsl; }
            set { ftpBaseSetting.UseSsl = value; }
        }

        public int FtpPortNumber
        {
            get { return ftpBaseSetting.PortNumber; }
            set { ftpBaseSetting.PortNumber = value; }
        }

        public string TcpHostAddress
        {
            get { return tcpBaseSetting.HostAddress; }
            set { tcpBaseSetting.HostAddress = value; }
        }

        public int TcpPortNumber
        {
            get { return tcpBaseSetting.PortNumber; }
            set { tcpBaseSetting.PortNumber = value; }
        }

        public bool TcpSsl
        {
            get { return tcpBaseSetting.UseSsl; }
            set { tcpBaseSetting.UseSsl = value; }
        }

        public string LogFileDirectory
        {
            get { return logFileDirectory; }
            set
            {
                logFileDirectory = value;
                ftpBaseSetting.LogFileDirectory = value;
                tcpBaseSetting.LogFileDirectory = value;
            }
        }
    }
}
